//
//  CTCResponderQuestionCell.m
//  ConsultantVersion
//
//  Created by 李小龙 on 2017/3/27.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "CTCResponderQuestionCell.h"

@interface CTCResponderQuestionCell()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet HZPhotoGroup *photoGroup;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoGroupHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoViewTopLayout;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@end
@implementation CTCResponderQuestionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


-(void)setQuestionModel:(CTCQuestionModel *)questionModel
{
    _questionModel = questionModel;
    
    [SDWebImageTool imageView:self.headImageView imageName:questionModel.headImg placeHolder:@"default-head" showProgress:NO];
    self.nameLabel.text = questionModel.name;
    self.contentLabel.text = questionModel.content;
    self.dateLabel.text = [NSDate stringFromTimestamp:questionModel.date];
    
    [self showImageViewQuestionModel:questionModel];
    
    if ([questionModel.status integerValue] == 1) {
        self.statusLabel.backgroundColor = HEXCOLOR(0x2daee5);
        self.statusLabel.text = @"已采纳";
    } else if ([questionModel.status integerValue] == 4) {
        self.statusLabel.backgroundColor = HEXCOLOR(0xff0000);
        self.statusLabel.text = @"已过期";
    }
    else {
        self.statusLabel.backgroundColor = HEXCOLOR(0xf79e06);
        self.statusLabel.text = @"未采纳";
    }
    
}

- (void)showImageViewQuestionModel:(CTCQuestionModel *)questionModel
{
    if (!self.questionModel || !self.questionModel.imgs || !self.questionModel.imgs.length) {
        _photoGroup.photoItemArray = @[];
        [_photoGroup setHeight:0];
        _photoGroupHeight.constant = 0;
        _photoViewTopLayout.constant = 0;
        return;
    }
    
    NSMutableArray *images = [@[] mutableCopy];
    
    NSArray *arr = [_questionModel.imgs componentsSeparatedByString:@","];
    
    [arr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [images addObject:[NSString stringWithFormat:@"%@/%@/%@", kMainBaseUrl, kShowImage, obj]];
    }];
    
    _photoGroup.photoItemArray = images;
    _photoGroupHeight.constant = _photoGroup.height;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
